<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CRUD_Model extends CI_Model
{
	private $table;

	function __construct()
	{
		parent::__construct();
	}

	function Insert($data)
	{
		$this->db->insert($this->table, $data);
		return $this->db->insert_id();
	}

	function Update($update_array, $data)
	{
		foreach ($update_array as $key => $value)
			$this->db->where($key, $value);
		$this->db->update($this->table, $data);
	}

	function Delete($delete_array)
	{
        foreach ($delete_array as $key => $value)
			$this->db->where($key, $value);
        $this->db->delete($this->table);
    }

    function Select($select_array)
    {
	    $this->db->select($select_array);
	    $query = $this->db->get($this->table);
	    return $query->result_array();
    }
    
    function SelectWhere($select_array)
    {
    	foreach ($select_array as $key => $value)
    		$this->db->where($key, $value);
    	$query = $this->db->get($this->table);
    	return $query->result_array();
    }

    function SelectMax($field)
    {
    	$this->db->select_max($field);
    	$query = $this->db->get($this->table);
    	return $query->result_array();
    }

    function SelectMin($field)
    {
    	$this->db->select_min($field);
    	$query = $this->db->get($this->table);
    	return $query->result_array();
    }

    function SelectAvg($field)
    {
    	$this->db->select_avg($field);
    	$query = $this->db->get($this->table);
    	return $query->result_array();
    }

    function SelectSum($field)
    {
    	$this->db->select_sum($field);
    	$query = $this->db->get($this->table);
    	return $query->result_array();
    }

}